USE [CTEM-DB-v1]
GO

/****** Object:  StoredProcedure [dbo].[WorkerSalary_search]    Script Date: 02/10/2012 11:14:08 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




-- =============================================
-- Author:		TienDH
-- Create date: 12/05/2011
-- Description:	Get full employee's information
-- =============================================
CREATE PROCEDURE [dbo].[WorkerSalary_search]
		@Name             nvarchar(250),
		@ConstructionID   bigint,
		@month			  Datetime
AS
BEGIN
	SELECT	e.*,p.Username,c.ConstructionName
	FROM	WorkersSalary e
	LEFT OUTER JOIN Construction c
	ON      e.ConstructionID = c.ConstructionID
	LEFT OUTER JOIN Employee p
	ON      p.EmployeeID = e.ManagerID
	WHERE e.Name like ISNULL(@Name,e.Name)
	AND   e.ConstructionID =ISNULL(@ConstructionID,e.ConstructionID)
	AND   ((MONTH(e.FromDate)= MONTH(@month) AND YEAR(e.FromDate)= YEAR(@month))
	OR	   (MONTH(e.ToDate)= MONTH(@month) AND YEAR(e.ToDate)= YEAR(@month)))
END




GO

